package com.icinfo.cloud.provider.punish.common.datareport.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.exception.DataReportException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.common.utils.SpringContextUtil;
import com.icinfo.cloud.provider.punish.common.datareport.dto.CaseDataReportRecordQueryDto;
import com.icinfo.cloud.provider.punish.common.datareport.dto.CaseDataReportRequestCommonDto;
import com.icinfo.cloud.provider.punish.common.datareport.enums.CaseDataReportOptTypeEnum;
import com.icinfo.cloud.provider.punish.common.datareport.enums.ReportDataTypeEnum;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseDataReportRecordService;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseDataReportService;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseDataReportStageInfoService;
import com.icinfo.cloud.provider.punish.common.datareport.vo.CaseDataReportRecordVo;
import com.icinfo.cloud.provider.punish.common.electricsent.dto.DocumentSendRecordQueryDto;
import com.icinfo.cloud.provider.punish.common.electricsent.enums.DocumentSendStatusEnum;
import com.icinfo.cloud.provider.punish.common.electricsent.service.IDocumentSendRecordService;
import com.icinfo.cloud.provider.punish.common.electricsent.vo.DocumentSendRecordVo;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseMainDetailAuxiliaryInfoRequest;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CasePartiesRecordQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.CaseTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.HandleTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartiesReasonTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseDocumentRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseMainDetailAuxiliaryInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseMainDetailInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseMainDetailSimpleInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseMainInfoVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CasePartiesInfoVo;
import com.icinfo.framework.common.web.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述：案件数据上报接口实现类-处罚告知信息
 *
 * @author xiangyuyu
 * @date 2022/6/13 20:04
 */
@Slf4j
@Service
public class CaseDataReportInformServiceImpl implements ICaseDataReportService {

    private static final String TERRITORY_CODE_PREFIX = "001";
    /**
     * 行政处罚事项告知推送接口
     */
    private static final String INFORM_HTTP = "Af5fA3wf55nzOf2e.htm";
    @Resource
    private ICaseMainDetailInfoService caseMainDetailInfoService;
    @Resource
    private ICaseDocumentRecordService caseDocumentRecordService;
    @Resource
    private IDocumentSendRecordService documentSendRecordService;
    @Resource
    private ICaseMainInfoService caseMainInfoService;
    @Resource
    private ICaseDataReportStageInfoService caseDataReportStageInfoService;
    @Resource
    private ICaseDataReportRecordService caseDataReportRecordService;
    @Resource
    private CaseDataReportBasicServiceImpl basicService;
    @Resource
    private CaseDataReportInvestigateServiceImpl investigateService;
    @Resource
    private ICasePartiesRecordService casePartiesRecordService;
    @Resource
    private ICaseMainDetailAuxiliaryInfoService caseMainDetailAuxiliaryInfoService;
    @Resource
    private ICaseMainDetailSimpleInfoService caseMainDetailSimpleInfoService ;
    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;

    /**
     * 描述：数据上报-inform
     *
     * @param dto          {@link CaseDataReportRequestCommonDto}
     * @param partyInfo    {@link CasePartiesInfoVo} 当事人信息
     * @param caseMainInfo {@link CaseMainInfoVo} 案件主体信息
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @Override
    public Result<String> singleCaseReport(CaseDataReportRequestCommonDto dto,CasePartiesInfoVo partyInfo, CaseMainInfoVo caseMainInfo) {
        log.info("dataReportInform start... dto:{}", dto);
        String caseId = dto.getCaseId();
        String optType = dto.getOptType();
        if(!ObjectUtils.isEmpty(optType)){
            if(!CaseDataReportOptTypeEnum.isLegalEnumCode(optType)){
                throw new BusinessException("请指定有效的数据上报更新类型枚举(I：新增， U：修改； D：删除)");
            }
        }
        if (!caseDataReportRecordService.personalCheckIsAllowDataReport(caseId, null)) {
            log.info("该案件暂不开启数据上报-caseId:{}", caseId);
            return Result.error("该案件暂不开启数据上报-caseId:" + caseId);
        }
        List<CasePartiesInfoVo> partiesInfo = new ArrayList<>();
        if (ObjectUtils.isEmpty(partyInfo)) {
            //获取当事人信息
            if (ObjectUtils.isEmpty(caseMainInfo)) {
                caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
            }
            String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();
            String handleType = caseMainInfo.getHandleType();
            CasePartiesRecordQueryDto queryDto = new CasePartiesRecordQueryDto(caseId, null, YesOrNoEnum.NO.getCode());
            partiesInfo = casePartiesRecordService.getCasePartiesInfoList(queryDto);
            if (!(PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                    && HandleTypeEnum.PART_PUNISH.getCode().equals(handleType))
            ) {
                //只取第一个当事人信息
                List<CasePartiesInfoVo> tmp = new ArrayList<>();
                tmp.add(partiesInfo.get(Constant.INTEGER_0));
                partiesInfo = tmp;
                partiesInfo.forEach(p -> p.setPartyId(null));
            }
        } else {
            partiesInfo.add(partyInfo);
        }

        for (CasePartiesInfoVo p : partiesInfo) {
            String partyId = p.getPartyId();
            try {
                if (caseDataReportRecordService.getIsAllowDataReport(caseId)) {
                    String errorMsg = "";
                    if(ObjectUtils.isEmpty(caseMainInfo)){
                        //根据案件id查询案件信息
                        caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
                    }
                    String caseType = caseMainInfo.getCaseType();
                    if(CaseTypeEnum.SIMPLE_PROCEDURE.getCode().equals(caseType)){
                        //简易处罚直接跳过
                        return Result.success("简易处罚直接跳过处罚告知信息数据上报");
                    }
                    String uri = INFORM_HTTP;
                    String reportDataType = ReportDataTypeEnum.INFORM.getCode();
                    JSONObject tmpData = reportDataCollect(caseMainInfo, reportDataType,false,p, optType);
                    JSONObject reportData = new JSONObject(8);
                    reportData.put("reportActionType", !ObjectUtils.isEmpty(optType)?optType:tmpData.get("reportActionType"));
                    reportData.put("envFlag", tmpData.get("envFlag"));
                    tmpData.remove("envFlag");
                    tmpData.remove("reportActionType");
                    reportData.put("informInfo", tmpData);
                    Map<String, String> params = new HashMap<>(20);
                    for (Map.Entry<String, Object> e : reportData.entrySet()) {
                        params.put(e.getKey(), (ObjectUtils.isEmpty(e.getValue()) ? "" : e.getValue().toString()));
                    }
                    errorMsg = caseDataReportRecordService.dataReport(uri, reportDataType, params, caseMainInfo);
                    log.info("dataReportInform end");
                    if (ObjectUtils.isEmpty(errorMsg)) {
                        caseDataReportStageInfoService.dealAfterReport(caseId, true, ReportDataTypeEnum.INFORM.getCode(), null,partyId);
                    } else {
                        if (errorMsg.contains(Constant.STRING_RECORD_EXISTS)) {
                            caseDataReportStageInfoService.dealAfterReport(caseId, true, ReportDataTypeEnum.INFORM.getCode(), errorMsg,partyId);
                        } else if(errorMsg.contains(Constant.STRING_ERROR_SIGN)) {
                            caseDataReportRecordService.reportAgain(dto, partyInfo, caseMainInfo, this, reportDataType);
                        } else {
                            caseDataReportStageInfoService.dealAfterReport(caseId, false, ReportDataTypeEnum.INFORM.getCode(), errorMsg,partyId);
                        }
                        return Result.error(errorMsg);
                    }
                } else {
                    String tmpMsg = "该部门是否允许上报数据按钮处于关闭状态,caseId:" + caseId;
                    throw new BusinessException(tmpMsg);
                }
            } catch (Exception e) {
                e.printStackTrace();
                caseDataReportStageInfoService.dealAfterReport(caseId, false, ReportDataTypeEnum.INFORM.getCode(), e.getMessage(),partyId);
                return Result.error("dataReportInform catch exception：" + e.getMessage());
            }
        }
        return Result.success("上报成功");
    }

    /**
     * 描述：收集数据上报-事先告知信息
     *
     * @param caseMainInfoVo   {@link CaseMainInfoVo}
     * @param reportDataType   上报数据类型
     * @param isUpdateReReport 是否更新补推
     * @param partyInfo        {@link CasePartiesInfoVo} 当事人信息
     * @param optType          更新类型
     * @return {@link JSONObject} 上报数据内容
     * @author xiangyuyu
     * @date 2022-03-31 23:18
     */
    @Override
    public JSONObject reportDataCollect(CaseMainInfoVo caseMainInfoVo, String reportDataType, boolean isUpdateReReport, CasePartiesInfoVo partyInfo, String optType) {
        JSONObject returnInfo = new JSONObject();
        log.info("collectReportCaseInformInfo start...param-caseMainInfo:{},reportDataType:{}", caseMainInfoVo, reportDataType);
        JSONObject informInfo = new JSONObject();
        String caseId = caseMainInfoVo.getId();
        String caseTerritoryCode = caseMainInfoVo.getCaseTerritoryCode();
        String sourceDeptCode = TERRITORY_CODE_PREFIX + caseTerritoryCode;
        CaseDataReportRecordQueryDto queryDto = new CaseDataReportRecordQueryDto();
        String partyId = partyInfo.getPartyId();
        queryDto.setCaseId(caseId);
        queryDto.setReportDataType(reportDataType);
        queryDto.setIsTestData(YesOrNoEnum.YES.getCode());
        queryDto.setPartyId(partyId);
        //默认测试数据1
        String envFlag = Constant.STRING_1;
        if (SpringContextUtil.checkIsPrdProfile()) {
            queryDto.setIsTestData(YesOrNoEnum.NO.getCode());
            envFlag = Constant.STRING_0;
        }

        List<CaseDataReportRecordVo> list = caseDataReportRecordService.getCaseDataReportRecord(queryDto);
        String reportActionType = "I";
        if (!ObjectUtils.isEmpty(list) && list.size() > 0) {
            CaseDataReportRecordVo latestRecord = list.get(Constant.INTEGER_0);
            String latestReportResult = latestRecord.getReportResult();
            if (!Constant.STRING_0.equals(latestReportResult)) {
                String oriActionType = latestRecord.getReportActionType();
                reportActionType = "U".equals(oriActionType) ? oriActionType : "I";
            } else {
                reportActionType = "U";
            }
        }



        informInfo.put("recordUniqueIdentity", BaseUtil.createUid());
         /*
            如果当事人id为空，则说明是单当事人/多当事人合并处罚，
            则caseId作为 punishBaseInfoCode，
            否则取当事人id作为 punishBaseInfoCode
         */
        String uid = partyId;
        //是否是多当事人分别处罚
        boolean isMultiplePartiesAndPartPunish = !ObjectUtils.isEmpty(partyId)?true:false;
        if(!isMultiplePartiesAndPartPunish){
            uid = caseId;
        }
        informInfo.put("punishBaseInfoCode", uid);

        String caseType = caseMainInfoVo.getCaseType();
        //获取案件详细信息
        CaseMainDetailInfo caseMainDetailInfo;
        CaseMainDetailSimpleInfo caseMainDetailSimpleInfo = null;
        if(CaseTypeEnum.SIMPLE_PROCEDURE.getCode().equals(caseType)){
            caseMainDetailInfo = new CaseMainDetailInfo();
            //简易处罚
            caseMainDetailSimpleInfo = caseMainDetailSimpleInfoService.getCaseMainDetailSimpleInfo(caseId);
            if(ObjectUtils.isEmpty(caseMainDetailSimpleInfo)){
                throw new BusinessException("未匹配到简易处罚的案件详情信息-caseId:"+caseId);
            }
            caseMainDetailInfo.setInvestigationEndDate(caseMainInfoVo.getCaseRegistTime()+"");
        }  else {
            caseMainDetailInfo  = caseMainDetailInfoService.getCaseMainDetailByCaseId(caseId);
        }

        String investigationEndDate = caseMainDetailInfo.getInvestigationEndDate();
        String punishKind;
        if(isMultiplePartiesAndPartPunish){
            //获取案件详情补充表信息
            CaseMainDetailAuxiliaryInfoRequest request = new CaseMainDetailAuxiliaryInfoRequest(caseId,partyId);
            List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryList = caseMainDetailAuxiliaryInfoService.getCaseMainDetailAuxiliaryInfo(request);
            if(!ObjectUtils.isEmpty(caseMainDetailAuxiliaryList) && caseMainDetailAuxiliaryList.size() > 0){
                CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryList.get(Constant.INTEGER_0);
                punishKind = caseMainDetailAuxiliaryInfo.getPunishKinds();

            } else {
                punishKind = Constant.STRING_HORIZONTAL_BARS;
            }
        } else {
            punishKind = caseMainDetailInfo.getPunishKinds();
        }

        punishKind = caseMainDetailInfo.getPunishKinds();
        if(!ObjectUtils.isEmpty(caseMainDetailSimpleInfo)){
            punishKind = caseMainDetailSimpleInfo.getPunishKinds();
        }

        informInfo.put("investigateEndDate", investigationEndDate);
        /*
        告知方式：
        数据上报规则：
            01-口头
            02-书面
         */
        informInfo.put("informMode", "02");
        //获取处罚告知种类
        String informPunishType = "";
        Map<String, String> punishTypeMap = new HashMap<>(16);
        punishTypeMap.put("警告", "01");
        punishTypeMap.put("罚款", "02");
        punishTypeMap.put("没收违法所得、没收非法财物", "03");
        punishTypeMap.put("责令停产停业", "04");
        punishTypeMap.put("暂扣或者吊销许可证、暂扣或者吊销执照", "05");
        punishTypeMap.put("吊销许可证", "05");
        punishTypeMap.put("行政拘留", "06");
        punishTypeMap.put("其他", "99");
        if (!ObjectUtils.isEmpty(punishKind)) {
            String[] punishKindArr = punishKind.split(",");
            for (String s : punishKindArr) {
                String value = punishTypeMap.get(s);
                if (ObjectUtils.isEmpty(value)) {
                    informPunishType += "99^";
                } else {
                    informPunishType += value + "^";
                }
            }
        } else {
            //默认为99【正常业务逻辑不可能出现为空】
            informPunishType = "99";
        }
        if (informPunishType.endsWith("^")) {
            informPunishType = informPunishType.substring(0, informPunishType.length() - 1);
        }
        informInfo.put("informPunishType", informPunishType);
        // FIXME: 2022/4/1 目前是否听证默认否（1-需要听证/0-不需要听证/-1-无该流程）
        informInfo.put("ifHearingWitnesses", Constant.STRING_0);

        //权利告知[非必填]
        //informInfo.put("informRightType", informRightType);
        //送达日期
        //获取事先告知书的送达信息(CFGZS0D007)[听证类-CFGZSTZL3DCEE]
        String kindCode = Constant.STRING_KIND_CODE_CFGZS;
        //查询文书种类
        String documentCatalogCode;
        List<ConfigBusiParamDocumentInfo> configList = configBusiParamDocumentInfoService.getDocumentConfigInfoByDocumentKindCode(caseId,null,kindCode);
        if(!ObjectUtils.isEmpty(configList)){
            documentCatalogCode = configList.get(Constant.INTEGER_0).getDocumentCatalogCode();
        } else {
            throw new BusinessException("未匹配文书目录编码信息-caseId:" + caseId + ",kindCode:" + kindCode);
        }
        CaseDocumentRecord caseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, documentCatalogCode,partyId);
        LocalDateTime deliverTime;
        if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
            deliverTime = caseDocumentRecord.getSentTime();
            informInfo.put("deliverTime", deliverTime);
            informInfo.put("informDate", caseDocumentRecord.getDocumentApprovalTime());
        } else {
            // 不予处罚
            kindCode = Constant.STRING_KIND_CODE_DK2BYXZCFGZS;
            configList = configBusiParamDocumentInfoService.getDocumentConfigInfoByDocumentKindCode(caseId,null,kindCode);
            if(!ObjectUtils.isEmpty(configList)){
                documentCatalogCode = configList.get(Constant.INTEGER_0).getDocumentCatalogCode();
            } else {
                throw new BusinessException("未匹配文书目录编码信息-caseId:" + caseId + ",kindCode:" + kindCode);
            }
            caseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, documentCatalogCode,partyId);
            if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
                deliverTime = caseDocumentRecord.getSentTime();
                informInfo.put("deliverTime", deliverTime);
                informInfo.put("informDate", caseDocumentRecord.getDocumentApprovalTime());
            } else {
                throw new DataReportException("collectReportCaseInformInfo - 未找到文书记录 caseId,documentCatalogCode" + caseId + "," + documentCatalogCode);
            }
        }
        DocumentSendRecordQueryDto q = new DocumentSendRecordQueryDto();
        q.setCaseId(caseId);
        q.setDocumentId(caseDocumentRecord.getId());
        q.setSendStatus(DocumentSendStatusEnum.SEND_SUCCESS.getCode());
        q.setPartyId(partyId);
        List<DocumentSendRecordVo> documentSendRecordList = documentSendRecordService.getDocumentSendRecordList(q);
        String deliverMode = "06";
        if (!ObjectUtils.isEmpty(documentSendRecordList) && documentSendRecordList.size() > 0) {
            DocumentSendRecordVo sendRecord = documentSendRecordList.get(Constant.INTEGER_0);
            Map<String, String> sentWayMap = new HashMap<>(8);
            sentWayMap.put("直接送达", "01");
            sentWayMap.put("留置送达", "02");
            sentWayMap.put("委托送达", "03");
            sentWayMap.put("邮递送达", "04");
            sentWayMap.put("公告送达", "05");
            sentWayMap.put("其他方式送达", "99");
            sentWayMap.put("电子送达", "06");
            //默认电子送达
            deliverMode = ObjectUtils.isEmpty(sentWayMap.get(sendRecord.getSentWayName())) ? deliverMode : sentWayMap.get(sendRecord.getSentWayName());

        }
        //送达方式
        informInfo.put("deliverMode", deliverMode);

        informInfo.put("optType", !ObjectUtils.isEmpty(optType) ? optType :reportActionType);
        informInfo.put("envFlag", envFlag);
        informInfo.put("sourceDeptCode", sourceDeptCode);
        returnInfo.put("informInfo", informInfo);
        //到dataReport时清空该键值
        returnInfo.put("reportActionType", !ObjectUtils.isEmpty(optType)?optType:reportActionType);
        returnInfo.put("envFlag", envFlag);
        log.info("collectReportCaseInformInfo end...result-returnInfo", returnInfo);
        return returnInfo;
    }


    /**
     * 【V2.0.0】描述：处罚告知信息-数据批量上报
     * @param baseInfoReportFailCaseIdList 上报失败的案件id列表
     * @return 上报失败案件id列表
     * @author xiangyuyu
     * @date 2022-06-13 16:02
     */
    @Override
    public List<String> batchCaseReport(List<String> baseInfoReportFailCaseIdList) {
        if(ObjectUtils.isEmpty(baseInfoReportFailCaseIdList)){
            baseInfoReportFailCaseIdList = new ArrayList<>();
        }
        LocalDateTime startTime = LocalDateTime.now();
        log.info("basicInfoReport start-startTime:{}", startTime);
        //3、查看2天前是否存在"事先告知书送达"的案件
        List<String> shouldUploadInformInfo = caseDocumentRecordService.getCaseIdListShouldReportInformInfo();
        if (!ObjectUtils.isEmpty(shouldUploadInformInfo) && shouldUploadInformInfo.size() > 0) {
            reportInformData(baseInfoReportFailCaseIdList, shouldUploadInformInfo);
        } else {
            log.info("date:{},无事先告知书送达",startTime);
        }
        LocalDateTime endTime = LocalDateTime.now();
        Duration duration = Duration.between(startTime, endTime);
        long seconds = duration.getSeconds();
        log.info("basicInfoReport end-endTime:{},consume:{} s", endTime, seconds);
        return baseInfoReportFailCaseIdList;
    }

    /**
     * 【V2.0.0】描述：处罚告知信息-数据批量上报
     * @param baseInfoReportFailCaseIdList 上报失败的案件id列表
     * @param punishDecideCaseIdList 范围内，处罚决定案件ID列表
     * @return 上报失败案件id列表
     * @author mahan
     * @date 2022-10-20 16:02
     */
    public List<String> batchCaseReport(List<String> baseInfoReportFailCaseIdList, List<String> punishDecideCaseIdList) {
        if(ObjectUtils.isEmpty(baseInfoReportFailCaseIdList)){
            baseInfoReportFailCaseIdList = new ArrayList<>();
        }
        LocalDateTime startTime = LocalDateTime.now();
        log.info("basicInfoReport start-startTime:{}", startTime);
        //3、查看2天前是否存在"事先告知书送达"的案件
        List<String> shouldUploadInformInfo = caseDocumentRecordService.getCaseIdListShouldReportInformInfo(punishDecideCaseIdList);
        if (!ObjectUtils.isEmpty(shouldUploadInformInfo) && shouldUploadInformInfo.size() > 0) {
            reportInformData(baseInfoReportFailCaseIdList, shouldUploadInformInfo);
        } else {
            log.info("date:{},无事先告知书送达",startTime);
        }
        LocalDateTime endTime = LocalDateTime.now();
        Duration duration = Duration.between(startTime, endTime);
        long seconds = duration.getSeconds();
        log.info("basicInfoReport end-endTime:{},consume:{} s", endTime, seconds);
        return baseInfoReportFailCaseIdList;
    }

    /**
     * 上报数据
     * @param baseInfoReportFailCaseIdList
     * @param shouldUploadInformInfo
     */
    private void reportInformData(List<String> baseInfoReportFailCaseIdList, List<String> shouldUploadInformInfo) {
        log.info("事先告知书送达数量:{}", shouldUploadInformInfo.size());
        List<String> finalBaseInfoReportFailCaseIdList = baseInfoReportFailCaseIdList;
        shouldUploadInformInfo.forEach(e -> {
            if (!finalBaseInfoReportFailCaseIdList.contains(e)) {
                CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(e);
                if (!caseDataReportRecordService.personalCheckIsAllowDataReport(e, caseMainInfo)) {
                    return;
                }
                String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();
                String handleType = caseMainInfo.getHandleType();
                CasePartiesRecordQueryDto queryDto = new CasePartiesRecordQueryDto(e,null,YesOrNoEnum.NO.getCode());
                List<CasePartiesInfoVo> partiesInfo = casePartiesRecordService.getCasePartiesInfoList(queryDto);
                if (!(PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                        && HandleTypeEnum.PART_PUNISH.getCode().equals(handleType))
                ) {
                    //只取第一个当事人信息
                    List<CasePartiesInfoVo> tmp = new ArrayList<>();
                    tmp.add(partiesInfo.get(Constant.INTEGER_0));
                    partiesInfo = tmp;
                    partiesInfo.forEach(p->p.setPartyId(null));
                }
                CaseDataReportRequestCommonDto dto = new CaseDataReportRequestCommonDto();
                dto.setCaseId(e);
                for (CasePartiesInfoVo partyInfo : partiesInfo) {
                    String partyId = partyInfo.getPartyId();
                    if(PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)){
                        //初始化数据上报阶段信息
                        caseDataReportStageInfoService.initCaseReportStageInfo(e,partyId);
                    }
                    //校验是否需要上报
                    boolean isShouldReport = caseDataReportStageInfoService.checkIsShouldReport(ReportDataTypeEnum.INFORM.getCode(), e,partyId);
                    if (isShouldReport) {
                        //判断案件基础信息是否上报
                        if (!caseDataReportStageInfoService.checkStageInfoIsReportSuccess(ReportDataTypeEnum.BASE.getCode(), e,partyId)) {
                            //未上报
                            Result<String> result = basicService.singleCaseReport(dto,partyInfo,caseMainInfo);
                            if (!caseDataReportRecordService.analyseResultToJudgeIsReportSuccess(result)) {
                                finalBaseInfoReportFailCaseIdList.add(e);
                            } else {
                                singleCaseReport(dto,partyInfo,caseMainInfo);
                            }
                        } else {
                            singleCaseReport(dto,partyInfo,caseMainInfo);
                        }
                    }
                    //多当事人的，查看对应调查取证信息是否数据上报
                    if(PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)){
                        //partyId 非空是多当事人分别处罚，几个当事人，要报几次调查取证信息，合并处罚报一次即可。
                        //判断调查取证信息是否数据上报
                        if (!caseDataReportStageInfoService.checkStageInfoIsReportSuccess(ReportDataTypeEnum.INVESTIGATE.getCode(), e,partyId)) {
                            //不管处罚告知是分别处罚还是合并处罚，这里都合并一条数据上报即可
                            Result<String> result = investigateService.singleCaseReport(dto,partyInfo,caseMainInfo);
                            if (!caseDataReportRecordService.analyseResultToJudgeIsReportSuccess(result)) {
                                finalBaseInfoReportFailCaseIdList.add(e);
                            }
                        }
                    }
                }
            }
        });
    }

    /**
     * 描述：单个案件重新数据上报（U）
     *
     * @param caseId 案件id
     * @param partyInfo    {@link CasePartiesInfoVo} 当事人信息
     * @param caseMainInfo {@link CaseMainInfoVo} 案件主体信息
     * @return {@link Result <String>} 上报结果
     * @author xiangyuyu
     * @date 2022-06-13 18:52
     */
    @Override
    public Result<String> singleCaseReportAgain(String caseId, CasePartiesInfoVo partyInfo, CaseMainInfoVo caseMainInfo) {
        return null;
    }

    /**
     * 描述：批量案件重新数据上报（U）
     *
     * @return {@link Result <String>} 上报失败案件id列表
     * @author xiangyuyu
     * @date 2022-06-13 18:52
     */
    @Override
    public List<String> batchCaseReportAgain() {
        return null;
    }
}
